package com.alignet.gn.web;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.apache.commons.lang.ArrayUtils;

import com.alignet.gn.util.GNUtils;

public class MessagesController {

	public MessagesController(final String sumary, final String detail) {	} // no usado


	
	public static String[] getMessage(final String messageKey){
		
		String ms[] = GNUtils.getMessage(messageKey).split("-");
		if(ms.length==1){
			ms = (String[]) ArrayUtils.add(ms, ms[0]);
			ms[0] = "";
		}
		return ms;
	}

	public static void addInfo(final String messageKey) {
		String[] ms = getMessage(messageKey);

		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,ms[0], ((ms.length==2)?ms[1]:"")));
	}

	public static void addWarn(final String messageKey) {
		String[] ms = getMessage(messageKey);
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,ms[0], ((ms.length==2)?ms[1]:"")));
	}

	public static void addError(final String messageKey) {
		String[] ms = getMessage(messageKey);
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,ms[0], ((ms.length==2)?ms[1]:"")));
	}

	public static void addFatal(final String messageKey) {
		String[] ms = getMessage(messageKey);
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,ms[0], ((ms.length==2)?ms[1]:"")));
	}
}
